const {
    SyncHook,
    SyncBailHook,
    SyncWaterfallHook,
    SyncLoopHook,
    AsyncParallelHook,
    AsyncParallelBailHook,
    AsyncSeriesHook,
    AsyncSeriesBailHook,
    AsyncSeriesWaterfallHook
 } = require("../../tapable/lib/index");
 const hook = new AsyncSeriesHook(["arg1", "arg2", "arg3"]);
 hook.tapAsync('hook2', function (arg1, arg2, arg3) {
    console.log(arg1, arg2, arg3);
 })
 hook.tapAsync({
     name: 'hook1',
     bofore: ['hook2'],
 }, function (arg1, arg2, arg3) {
    console.log(arg1, arg2, arg3);
 })
 hook.tapAsync('hook3', function (arg1, arg2, arg3) {
    console.log(arg1, arg2, arg3);
 })
 hook.callAsync(1, 2, 3);
//  class Car {
//     constructor() {
//         this.hooks = {
//             accelerate: new SyncHook(["newSpeed"]),
//             break: new SyncHook(),
//             calculateRoutes: new AsyncSeriesWaterfallHook(["source", "target", "routesList"])
//         };
//     }

//     setSpeed(newSpeed, newSpeed2) {
//         this.hooks.accelerate.call(newSpeed, newSpeed2);
//     }

//     useNavigationSystemPromise(source, target) {
//         const routesList = [2,3,4,5,6];
//         return this.hooks.calculateRoutes.promise(source, target, routesList).then((data) => {
//             console.log(data);
//             return routesList;
//         });
//     }

//     useNavigationSystemAsync(source, target, callback) {
//         const routesList = new List();
//         this.hooks.calculateRoutes.callAsync(source, target, routesList, err => {
//             if(err) return callback(err);
//             callback(null, routesList.getRoutes());
//         });
//     }
// }
// const myCar = new Car();

// // Use the tap method to add a consument
// myCar.hooks.break.tap("WarningLampPlugin", () => warningLamp.on());
// // myCar.hooks.accelerate.tap("LoggerPlugin", (newSpeed, newSpeed2) => console.log(`Accelerating to ${JSON.stringify(newSpeed)}, ${newSpeed2}`));
// debugger
// myCar.hooks.calculateRoutes.tapPromise({
//     before: 'before',
//     after: 'after',
//     name: 'GoogleMapsPlugin',
// }, (source, target, routesList) => {
//     // return a promise
//     return new Promise(function (resolve) {
//         setTimeout(function () {
//             console.log(source, target, routesList);
//             resolve(source, target, routesList);
//         }, 1000);
//     });
// });
// myCar.hooks.calculateRoutes.tapPromise({
//     before: 'before2',
//     after: 'after3',
//     name: 'GoogleMapsPlugin',
// }, (source, target, routesList) => {
//     // return a promise
//     return new Promise(function (resolve) {
//         setTimeout(function () {
//             console.log(source, target, routesList);
//             resolve(source, target, routesList);
//         }, 2000);
//     });
// });
// // myCar.hooks.calculateRoutes.tapAsync("BingMapsPlugin", (source, target, routesList, callback) => {
// //     bing.findRoute(source, target, (err, route) => {
// //         if(err) return callback(err);
// //         routesList.add(route);
// //         // call the callback
// //         callback();
// //     });
// // });
// myCar.hooks.calculateRoutes.intercept({
//     call: (source, target, routesList) => { // 对传入的函数进行处理
//         console.log("Starting to calculate routes");
//     },
//     tap: function (tap) { // 对传入的对象tap对象进行处理
//         return 1;
//     },
//     register: (tapInfo) => { // 提前对tap进行处理
//         console.log(`${tapInfo.name} is doing it's job`);
//         console.log(tapInfo);
//         tapInfo.context = true; // 可以让所有的钩子有一个共同的对象
//         return tapInfo;
//     }
// });
// // // You can still use sync plugins
// // myCar.hooks.calculateRoutes.tap("CachedRoutesPlugin", (source, target, routesList) => {
// //     const cachedRoute = cache.get(source, target);
// //     if(cachedRoute)
// //         routesList.add(cachedRoute);
// // });
// myCar.useNavigationSystemPromise(2,3,4);